﻿@page "/"
@inject IIndexedDbFactory DbFactory

<button @onclick="@Create">Click me</button>
@code{
protected async Task Create()
{
    using (var db = await this.DbFactory.Create<ExampleDb>())
    {
        //var t = db.People.Include(x => x.Dog);
        //db.People.Remove(new Person()
        //{
        //    Id = 1,
        //    FirstName = "a",
        //    LastName = "b"
        //});
        for (int i = 0; i < 100; i++)
        {
            db.People.Add(new Person()
            {
                FirstName = Guid.NewGuid().ToString(),
                LastName = Guid.NewGuid().ToString()
            });
        }
        //await db.SaveChanges();
        //db.People.Add(new Person()
        //{
        //    Id = 1,
        //    FirstName = Guid.NewGuid().ToString(),
        //    LastName = Guid.NewGuid().ToString()
        //});

        await db.SaveChanges();
    }

    //using (var db = await this.DbFactory.Create<ExampleDb>())
    //{
    //    Debug.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(db.People));
    //    var person = db.People.Single(x => x.Id == 1);

    //    person.FirstName = "This is 100% a first name";

    //    await db.SaveChanges();
    //}
}
}